$(function () {
    $('#mpanel4').slideVerify({
        type: 2,		//类型
        vOffset: 5,	//误差量，根据需求自行调整
        vSpace: 5,	//间隔
        imgName: ['1.jpg', '2.jpg'],
        imgSize: {
            width: '400px',
            height: '200px',
        },
        blockSize: {
            width: '40px',
            height: '40px',
        },
        barSize: {
            width: '400px',
            height: '40px',
        },
        ready: function () {
        },
        success: function () {
            alert('验证成功');
            window.location.href = "register.html";
        },
        error: function () {
        }
    });
})
//注册接口参数
function adduser(em, ph, name, pw, pw2) {
    var params = {
        contentType: "application/json;charset-UTF-8",
        datatype: 'json',
        email: em,
        mobile: ph,
        name: name,
        password: pw,
        password2: pw2
    };
    return params;
}

//注册
function add() {
    if (a == true && b == true && c == true && d == true) {
        if ($("#dsyxy").prop("checked")) {
            var name = $("#name input").val();
            var phone = $("#phone input").val();
            var email = $("#email input").val();
            var password = $("#password input").val();
            var password2 = $("#onpassword input").val();
            var url = "/open/client"; // 接口 
            var params = {
                'email': email,
                'mobile': phone,
                'name': name,
                'password': password,
                'password2': password2
            };
            $.ajax({
                type: "post",
                url: "http://lex.itdida.com/itdida-api/open/client",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(params),
                dataType: 'json',
                success: function (data) {
                    if (data.statusCode == 200) {
                        alert("注册成功！");
                        window.location.href = "login.html";
                    }
                },
                error: function (data) {
                    alert(jQuery.parseJSON(data.responseText).data);
                }
            })
        } else {
            alert("您还未勾选递送易用户协议！");
        }
    }
}
var a;
var b;
var c;
var d;
//显示遮罩层
function showMask() {
    $("#mask").css("height", $('body').height());
    $("#mask").css("width", $('body').width());
    $("#mask").show();
}
//手机正则表达式
function regphone() {
    var pattern = /^1([3-9][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
    $("#phone input").on('blur', function () {
        var phone = $("#phone input").val();
        if (!pattern.test(phone)) {
            $("#phone span.tishi").remove();
            $("#phone").append("<span class='tishi' style='font-size:14px;color:red;'>*手机号格式错误*</span>");
            a = false;

        }
        else {
            $("#phone span.tishi").remove();
            a = true;

        }
    });
}
//邮箱正则表达式
function regemail() {
    var emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    $("#email input").on('blur', function () {
        var email = $("#email input").val();
        if (!emailReg.test(email)) {
            $("#email span.tishi").remove();
            $("#email").append("<span class='tishi' style='font-size:14px;color:red;'>*邮箱格式错误*</span>");
            b = false;
        }
        else {
            $("#email span.tishi").remove();
            b = true;
        }
    });
}
//密码正则表达式
function regpassword() {
    var pwReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;
    $("#password input").on('blur', function () {
        var password = $("#password input").val();
        var b = $("#onpassword input").val();
        if (!pwReg.test(password)) {
            $("#password span.tishi").remove();
            $("#password").append("<span class='tishi' style='font-size:14px;color:red;'>*密码格式错误*</span>");
            c = false;
        }
        else {
            $("#password span.tishi").remove();
            c = true;
        }
    });
}
//重复密码验证
function onpassword() {
    $("#onpassword input").on('blur', function () {
        var a = $("#password input").val();
        var b = $("#onpassword input").val();
        if (a != b) {
            $("#onpassword span.tishi").remove();
            $("#onpassword").append("<span class='tishi' style='font-size:14px;color:red;'>*两次密码输入不一致*</span>");
            d = false;
        } else {
            $("#onpassword span.tishi").remove();
            d = true;
        }
    });

}
//下拉框搜索
$(function () {
    $(".select2").select2();
    //正则
    regphone();
    regemail();
    regpassword();
    onpassword();
});